//
// 打印两个有序链表的公共部分
// Created by Liming Shao on 10/24/2017.
//

#include "B034.h"

#include <iostream>

void B034::getCommonPart(std::list<int> head1, std::list<int> head2) {
    std::list<int>::iterator it1 = head1.begin();
    std::list<int>::iterator it2 = head2.begin();
    while(it1!=head1.end() && it2 != head2.end()){
        if(*it1 == *it2){
            std::cout << *it1 << " ";
            it1++;
            it2++;
        }else if(*it1 <= *it2){
            it1++;
        }
        else {
            it2++;
        }
    }
}

void B034::test() {
    std::list<int> stack1{1,3,5,7,8,9};
    std::list<int> stack2{2,3,4,5,6,8,9,10};
    this->getCommonPart(stack1, stack2);
}
